package edu.tapestry.iddb.client.pages.message;

import iddb.MessagePOJO;
import iddb.MessagesInfo;
import iddb.PluginIdentificator;

import java.util.List;

import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.annotations.ApplicationState;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.beaneditor.BeanModel;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.BeanModelSource;

import edu.tapestry.iddb.client.webService.CommandsGenerator;
import edu.tapestry.iddb.client.webService.IDDBProxy;

public class RecievedListMessage {

	@ApplicationState
	private IDDBProxy proxy;

	@Persist
	private PluginIdentificator ident;
	
	@Property
	private MessagePOJO message;
	
	@Inject
	private BeanModelSource beanModelSource;

	@Inject
	private ComponentResources resources;

	private BeanModel<MessagePOJO> model;

	public Object initialize(PluginIdentificator ident) {

		this.ident = ident;
		return this;
	}

	void pageLoaded() {
		this.model = beanModelSource.create(MessagePOJO.class, true, resources
				.getMessages());
		this.model.add("details", null);
	}
	
	public List<MessagePOJO> getMessages(){
		MessagesInfo response = (MessagesInfo)proxy.execute(CommandsGenerator.getMessagesCmd(this.ident));
		return response.getList();
	}

}
